<?php 
class App_Page_Pager_AdminBlock extends Main_Pager
{
	/**
	 * @var array
	 */
	protected $_fields = array(
		'id'   => array('simpleSearch' => true, 'sql' => 'page_block.id'),
		'name' => array('simpleSearch' => true, 'sql' => 'page_block.name'),
		'description' => array('simpleSearch' => true, 'sql' => 'page_block.description'),
		'f_active' => array('simpleSearch' => true, 'sql' => 'page_block.f_active'),	
	);
	
	/**
	 * @return void
	 */
	protected function _init()
	{
		$langCondition = ($this->_options['type'] == 0) ? "AND page_block.lang_id IS NULL" 
			: " AND page_block.lang_id={$this->_options['type']}"; 
		
		$pageCondition = "AND page_block.page_id={$this->_options['page_id']}";	
			
			
		$this->_config['base'] = "
			SELECT 
				page_block.id
				, page_block.name
				, page_block.f_active
				, page_block.description  	
			FROM
				page_block
			WHERE true {$langCondition} {$pageCondition}		
		";
				
		$this->_config['count'] = "
			SELECT 
				COUNT(page_block.id)
			FROM
				page_block
			WHERE true {$langCondition}	{$pageCondition}
		";		

		$this->_service = new App_Page_Service_Block();
						
		parent::_init();			
	}
	
	/**
	 * @param int|string $primary
	 * @return bool
	 */
	protected function _deleteItem($primary) 
	{
		return $this->_service->deleteItem($primary);
	}
}


